package logic

import (
	"context"

	"go-zero-all/apps/user/pb/pb"
	"go-zero-all/apps/user/rpc/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type PingLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewPingLogic(ctx context.Context, svcCtx *svc.ServiceContext) *PingLogic {
	return &PingLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *PingLogic) Ping(in *pb.Request) (*pb.Response, error) {
	var id int64
	if in.Ping == "you" {
		id = 1
	} else if in.Ping == "me" {
		id = 2
	} else {
		id = 3
	}

	user, err := l.svcCtx.UserModel.FindOne(l.ctx, id)
	if err != nil {
		return nil, err
	}
	return &pb.Response{Pong: user.Name}, nil
}
